package com.luoqiu.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.luoqiu.entities.Result;
import com.luoqiu.sentinel.myhandler.CustomerHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 洛秋y
 * @date 2020/11/25 9:28
 */
@RestController
public class RateLimitController {

    @GetMapping(value = "/byResource")
    @SentinelResource(value = "byResource", blockHandler = "handleException")
    public Result<String> byResource() {
        Result<String> result = new Result<>();
        result.setMsg("coco");
        return result;
    }

    public Result<String> handleException(BlockException exception) {
        Result<String> result = new Result<>();
        result.setMsg("error");
        return result;
    }

    @GetMapping(value = "/customer/handler")
    @SentinelResource(value = "customerHandler", blockHandlerClass = CustomerHandler.class, blockHandler = "handException2")
    public String get() {
        return "customer/handler";
    }
}
